﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using HackApp.Entities;

namespace HackApp.Models
{
    public class IdeaModel
    {
      [Required]
      [Display(Name = "Name")]
      public string Name { get; set; }

      [Required]
      [Display(Name = "Description")]
      public string Description { get; set; }

      [Display(Name = "Category")]
      public string Category { get; set; }

      public string Author { get; set; }

      public int Id { get; set; }

      public int VotesCount { get; set; }

      public IdeaDTO ToDTO()
      {
        IdeaDTO idea = new IdeaDTO();
        idea.Name = this.Name;
        idea.Category = this.Category;
        idea.Description = this.Description;
        idea.Id = this.Id;
        return idea;
      }


      public void ToVM(IdeaDTO idea)
      {
        if (idea.Name == null || idea.Description == null || idea.Author == null || idea.Id == null) throw new ArgumentException();
        else
        {
          this.Name = idea.Name;
          this.Description = idea.Description;
          this.Author = idea.Author;
          this.Id = idea.Id;
        }
      }

      public void ToVM(IdeaDTO idea, bool teaser)
      {
        ToVM(idea);
        if (teaser && idea.Description.Length > 300)
        {
            this.Description = idea.Description.Substring(0, 300) + "...";
        }
      }
    }
}